<?php
namespace Admin\Controller;
use Think\Controller;
class GamerController extends BaseController {
	//玩家列表
    public function gamerList(){
        $keywords=I('get.keywords');
        $keyvalue=trim(I('get.keyvalue'));
        if ($keywords!='' && $keyvalue!='') {
            $where='where '.$keywords.' like "%'.$keyvalue.'%" ';
        }else if ($keywords!='' && $keyvalue=='') {
            $where='';
        }else if ($keywords=='' && $keyvalue!='') {
            $where='where gamer_id like "%'.$keyvalue.'%" or openid like "%'.$keyvalue.'%" or phone like "%'.$keyvalue.'%" or nickname like "%'.$keyvalue.'%" ';
        }
        $re=M('')->query('select *,FROM_UNIXTIME(addtime, "%Y-%m-%d %H:%i:%S") as addtime from gm_gamer '.$where.'order by gamer_id asc');
        // var_dump($adminList);die;
        if (!$re) {
            $re='';
        }
        $data=$this->showPage($re);
        
        $this->assign('adminList',$data['arr']);
        $this->assign('page',$data['pageStr']);
        $this->assign('keywords',$keywords);
        $this->assign('keyvalue',$keyvalue);
        $this->display();
    }
    //充值记录
    public function payList(){
        $keywords=I('get.keywords');
        $keyvalue=trim(I('get.keyvalue'));
        if ($keywords!='' && $keyvalue!='') {
            if ($keywords=='truename') {
               $where='where a.'.$keywords.' like "%'.$keyvalue.'%" ';
            }else{
                $where='where p.'.$keywords.' like "%'.$keyvalue.'%" ';
            }
            
        }else if ($keywords!='' && $keyvalue=='') {
            $where='';
        }else if ($keywords=='' && $keyvalue!='') {
            $where='where p.openid like "%'.$keyvalue.'%" or a.truename like "%'.$keyvalue.'%" ';
        }
        $re=M('')->query('select p.*,FROM_UNIXTIME(p.addtime, "%Y-%m-%d %H:%i:%S") as addtime,a.truename from gm_pay p join gm_admin a on a.admin_id=p.admin_id '.$where.'order by p.id desc');
        if (!$re) {
            $re='';
        }
        $data=$this->showPage($re);
        
        $this->assign('adminList',$data['arr']);
        $this->assign('page',$data['pageStr']);
        $this->assign('keywords',$keywords);
        $this->assign('keyvalue',$keyvalue);
        $this->display();
    }
    //消费记录，type:1-开房间，2-买道具，3-赠送
    public function consumeList(){
        $keywords=I('get.keywords');
        $keyvalue=trim(I('get.keyvalue'));
        if ($keyvalue!='') {
            if ($keywords=='') {
                $where='where openid like "%'.$keyvalue.'%" ';
            }else{
                $where='where '.$keywords.' like "%'.$keyvalue.'%" ';
            }
        }else {
            $where='';
        }
        $re=M('')->query('select *,FROM_UNIXTIME(addtime, "%Y-%m-%d %H:%i:%S") as addtime from gm_consume '.$where.'order by id desc');
        if (!$re) {
            $re='';
        }
        $data=$this->showPage($re);
        
        $this->assign('adminList',$data['arr']);
        $this->assign('page',$data['pageStr']);
        $this->assign('keywords',$keywords);
        $this->assign('keyvalue',$keyvalue);
        $this->display();
    }
    //历史战绩
    public function recordList(){
        $keywords=I('get.keywords');
        $keyvalue=trim(I('get.keyvalue'));
        if ($keyvalue!='') {
            if ($keywords=='') {
                $where='where openid like "%'.$keyvalue.'%" ';
            }else{
                $where='where '.$keywords.' like "%'.$keyvalue.'%" ';
            }
            
        }else {
            $where='';
        }
        $re=M('')->query('select *,FROM_UNIXTIME(addtime, "%Y-%m-%d %H:%i:%S") as addtime from gm_record '.$where.'order by id desc');
        if (!$re) {
            $re='';
        }
        $data=$this->showPage($re);
        
        $this->assign('adminList',$data['arr']);
        $this->assign('page',$data['pageStr']);
        $this->assign('keywords',$keywords);
        $this->assign('keyvalue',$keyvalue);
        $this->display();
    }
    //账号封停
    public function blacklist(){
        $gamer_id=I('get.gamer_id');
        $status=I('get.status');
        $re=M('Gamer')->where('gamer_id='.$gamer_id)->save(array('status'=>$status));
        if ($re) {
            $this->ajaxReturn('success');
        }else{
            $this->ajaxReturn('false');
        }
    }
}